package com.qdxwx.data.service.course;

import com.qdxwx.common.page.PageRequest;
import com.qdxwx.data.mapper.course.CourseFileMapper;
import com.qdxwx.models.course.CourseFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * Qdx NetSchool Platform
 * @author qdxwx
 * @updateTime 2022/5/25
 * @description
 */
@Service
public class CourseFileServiceImpl implements CourseFileService{

    @Autowired
    private CourseFileMapper courseFileMapper;

    @Override
    public CourseFile get(int id) {
        if(id < 1) return null;
        return courseFileMapper.selectById(id);
    }

    @Override
    public List<CourseFile> getList(int courseId) {
        if(courseId < 1) return new ArrayList<>();
        CourseFile query = new CourseFile();
        query.setCourseId(courseId);
        return getList(query,null);
    }

    @Override
    public List<CourseFile> getList(CourseFile query, PageRequest page) {
        return courseFileMapper.selectList(query,page);
    }

    @Override
    public int count(CourseFile query) {
        return courseFileMapper.selectCount(query);
    }

    @Override
    public int insert(CourseFile courseFile) {
        courseFile.setCreateTime(LocalDateTime.now());
        return courseFileMapper.insert(courseFile);
    }

    @Override
    public int delete(int id) {
        if(id < 1) return 0;
        return courseFileMapper.deleteById(id);
    }

    @Override
    public int deleteByCourseId(int courseId) {
        if(courseId < 1) return 0;
        return courseFileMapper.deleteByCourseId(courseId);
    }
}
